Skip to content

feat(payments): Add account id build method#73

Open
Quentin-David-24 wants to merge 1 commit intomainfrom
feat/payments-account-id-build
Open

feat(payments): Add account id build method#73
Quentin-David-24 wants to merge 1 commit intomainfrom
feat/payments-account-id-build

Conversation

@Quentin-David-24
Copy link

@Quentin-David-24 Quentin-David-24 commented Feb 2, 2026

Fixes EN-708

@coderabbitai
Copy link

coderabbitai bot commented Feb 2, 2026

Walkthrough

A new utility class PaymentsAccountId has been introduced to handle construction of Base64-encoded payment account identifiers. The class provides a static Build method that validates inputs, decodes a Base64-encoded connector ID, escapes the reference, constructs a JSON string, and returns the Base64-encoded result without padding.

Changes

Cohort / File(s) Summary
New Payments Account Utility
src/main/java/com/formance/formance_sdk/utils/custom_helpers/PaymentsAccountId.java
Added public utility class with static Build(String, String) method that performs Base64 decoding, JSON construction, reference escaping, and Base64 encoding for payment account ID generation with input validation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A helper hops into the light,
Encoding accounts, making payments right,
Base64 dancing, JSON strings align,
PaymentsAccountId works just fine! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Description check ❓ Inconclusive No pull request description was provided by the author, making it impossible to assess whether the description relates to the changeset. Add a description explaining the purpose, motivation, and usage of the new PaymentsAccountId build method.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding an account ID build method to the payments module.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/payments-account-id-build

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In
`@src/main/java/com/formance/formance_sdk/utils/custom_helpers/PaymentsAccountId.java`:
- Around line 25-26: The JSON building in PaymentsAccountId currently only
escapes backslashes and quotes for `reference`, which misses control characters
and can produce invalid JSON; add a private helper method (e.g.,
escapeJson(String s) in the PaymentsAccountId class) that escapes backslash and
quote and converts control characters (\b, \f, \n, \r, \t) and any codepoint <
0x20 into their proper JSON escape sequences (use \u00XX for other control
chars), then replace the direct replace(...) call and pass
`escapeJson(reference)` into the String.format call that builds `json` (the code
referencing `connectorIdJson` and `reference`).

Comment on lines +25 to +26
String connectorIdJson = new String(Base64.getDecoder().decode(connectorId), StandardCharsets.UTF_8);
String json = String.format("{\"ConnectorID\":%s,\"Reference\":\"%s\"}", connectorIdJson, reference.replace("\\", "\\\\").replace("\"", "\\\""));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# First, locate and examine the PaymentsAccountId.java file
fd "PaymentsAccountId.java" --type f

Repository: formancehq/formance-sdk-java

Length of output: 155


🏁 Script executed:

# Check if the file exists and read its content
cat -n "src/main/java/com/formance/formance_sdk/utils/custom_helpers/PaymentsAccountId.java"

Repository: formancehq/formance-sdk-java

Length of output: 1948


🏁 Script executed:

# Search for JSON-related imports and utilities in the codebase
rg "import.*json|import.*JSON" --type java | head -20

Repository: formancehq/formance-sdk-java

Length of output: 367


🏁 Script executed:

# Check if there are existing JSON escaping patterns in the codebase
rg "escapeJson|JsonEscape|replace.*\\\\\\\\|StandardCharsets" --type java -B 2 -A 2 | head -40

Repository: formancehq/formance-sdk-java

Length of output: 4084


Escape JSON control characters in reference to prevent malformed IDs.

The current escaping only handles backslash and quote. Control characters like newline, tab, and other characters below 0x20 are not escaped, resulting in invalid JSON when such characters appear in reference. This breaks the account ID format expected by the Formance API.

Add a helper method to properly escape all JSON-required characters:

Suggested fix (local escape helper)
-        String json = String.format("{\"ConnectorID\":%s,\"Reference\":\"%s\"}", connectorIdJson, reference.replace("\\", "\\\\").replace("\"", "\\\""));
+        String json = String.format("{\"ConnectorID\":%s,\"Reference\":\"%s\"}", connectorIdJson, escapeJsonString(reference));
@@
     public static String Build(String connectorId, String reference) {
@@
     }
+
+    private static String escapeJsonString(String input) {
+        StringBuilder sb = new StringBuilder(input.length() + 16);
+        for (int i = 0; i < input.length(); i++) {
+            char c = input.charAt(i);
+            switch (c) {
+                case '\\': sb.append("\\\\"); break;
+                case '"': sb.append("\\\""); break;
+                case '\b': sb.append("\\b"); break;
+                case '\f': sb.append("\\f"); break;
+                case '\n': sb.append("\\n"); break;
+                case '\r': sb.append("\\r"); break;
+                case '\t': sb.append("\\t"); break;
+                default:
+                    if (c < 0x20) {
+                        sb.append(String.format("\\u%04x", (int) c));
+                    } else {
+                        sb.append(c);
+                    }
+            }
+        }
+        return sb.toString();
+    }
🤖 Prompt for AI Agents
In
`@src/main/java/com/formance/formance_sdk/utils/custom_helpers/PaymentsAccountId.java`
around lines 25 - 26, The JSON building in PaymentsAccountId currently only
escapes backslashes and quotes for `reference`, which misses control characters
and can produce invalid JSON; add a private helper method (e.g.,
escapeJson(String s) in the PaymentsAccountId class) that escapes backslash and
quote and converts control characters (\b, \f, \n, \r, \t) and any codepoint <
0x20 into their proper JSON escape sequences (use \u00XX for other control
chars), then replace the direct replace(...) call and pass
`escapeJson(reference)` into the String.format call that builds `json` (the code
referencing `connectorIdJson` and `reference`).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant